package com.wch.demo.actuator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

import com.wch.demo.configfile.entity.DefineYml;

/**
 * 自定义User健康检测
 * 访问：localhost:8080/health
 * @author WanChengHe
 *
 */
@Component
public class UserHealthIndicator implements HealthIndicator {

	@Autowired
	private DefineYml defineEntity;
		
	@Override
	public Health health() {
		// TODO Auto-generated method stub
		//健康检查的逻辑
		if(!(null == defineEntity.getBaseName())){
			//检查通过（新建对象）
			return new Health.Builder().withDetail("userNmae", defineEntity.getBaseName())
									   .withDetail("userSex", defineEntity.getBaseSex())
									   .withDetail("userAge", defineEntity.getBaseAge()).up().build();
		}else{
			//检查失败（静态方法）
			return Health.down().withDetail("userNmae", defineEntity.getBaseName())
					   .withDetail("userSex", defineEntity.getBaseSex())
					   .withDetail("userAge", defineEntity.getBaseAge()).withDetail("status", "down").build();
			
		}
		
		
	}

}
